package com.hongsheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hongsheng.mapper.CustomerMapper;
import com.hongsheng.pojo.Customer;
import com.hongsheng.pojo.Package;
import com.hongsheng.service.CustomerService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @description 客户service实现类,下面是用mybatisplus的自带的crud,免得重复的写crud操作
 **/
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public boolean insertCustomer(Customer customer) {
        return customerMapper.insertCustomer(customer)>0;
    }

    @Override
    public boolean updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer)>0;
    }

    @Override
    public IPage<Customer> getPage(int currentPage, int size, Customer customer) {
        //按条件查询
        LambdaQueryWrapper<Customer> wrapper=new LambdaQueryWrapper<>();
        if(customer.getId()!=null){
            wrapper.eq(Customer::getId,customer.getId());
        }
        wrapper.like(Strings.isNotEmpty(customer.getName()),Customer::getName,customer.getName());
        if(customer.getSex()!=null) {
            wrapper.eq(Customer::getSex, customer.getSex());
        }
        wrapper.like(Strings.isNotEmpty(customer.getType()),Customer::getType,customer.getType());
        Page<Customer> page=new Page<>(currentPage,size);
        Page<Customer> page1 = baseMapper.selectPage(page, wrapper);
        return page1;
    }
}
